home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / PRGMANIA / BFED.10 / INIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  5.3 KB  |  224 lines

  1. /*
  2.     file: init.c
  3.     utility:
  4.     date: 1989
  5.     author: Jim Charlton
  6.     modifications:
  7.         1996: C. Moreau: 
  8.     comments: 
  9. */
  10.  
  11. #include <string.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14.  
  15. #ifdef __PUREC__ 
  16. #include <aes.h>
  17. #include <tos.h>
  18. #include <vdi.h>
  19. #include <compend.h>
  20. #else
  21. #include <aesbind.h>
  22. #include <osbind.h>
  23. #include <vdibind.h>
  24. #endif
  25.  
  26. #include "e:\proging\c\libs\malib\alert.h"
  27. #include "e:\proging\c\libs\malib\appgpath.h"
  28. #include "e:\proging\c\libs\malib\resource.h"
  29.  
  30. #include "config.h"
  31. #include "dialog.h"
  32. #include "edit.h"
  33. #include "files.h"
  34. #include "init.h"
  35. #include "keys.h"
  36. #include "main.h"
  37. #include "menu.h"
  38. #include "onepage.c"
  39. #include "wind.h"
  40.  
  41. #include "bfed_rsc.h"
  42.  
  43. /*
  44.     Globals variables
  45. */
  46. int phys_handle;            /* vdi handle */
  47. int gl_hchar, gl_wchar;    /* sizes of window font */
  48. int xdesk, ydesk, wdesk, hdesk;    /* desktop sizes */
  49. int ver_aes, ver_tos;    /* version of AES and TOS */
  50. int pxyarray[8];    /* for vdi calls */
  51.  
  52. /*
  53.     locals functions
  54. */
  55. static void init_sys_vars(void);
  56. static void init_argv(int *argc, char **argv[]);
  57.  
  58. /* 
  59.     name: init
  60.     utility: Make all initializations 
  61.     comment: 
  62.         called from main.c.
  63.         Initialise the VDI, the system info vars (AES version,...),
  64.         load the ressource, initialise the modules (globals vars string
  65.         in the right language).
  66.         Get the ARGV command and open associated windows.
  67.     parameters: ARGV command
  68.     return:
  69.     date: 10 may 96
  70.     author: C.Moreau
  71.     modifications:
  72. */
  73. void init(int *argc, char **argv[])
  74. {
  75.     MFDB    desk_mfdb;
  76.  
  77.     init_sys_vars();        /* init the system information vars */
  78.     
  79.     rsrc_lang_load(PRG_NAME);    /* load ressources */
  80.     
  81.         /* initialise VDI for the general programm */
  82.     phys_handle = open_vwork(&desk_mfdb);
  83.     
  84.     if ( (desk_mfdb.fd_w < 640) || (desk_mfdb.fd_h < 200) )
  85.     {
  86.         rsc_alert(LOW_RES);
  87.         shutdown(2);
  88.     }
  89.     else
  90.     {
  91.         init_menu();        /* initialise module menu.c */
  92.         init_dialog();        /* initialise module dialog.c */
  93.         init_files();        /* initialise module files.c */
  94.         init_keys();        /* initialise module keys.c */
  95.     
  96.         set_table();    /*  makes two byte ascii hex table (onepage.c)  */    
  97.     
  98.         init_argv(argc, argv);    /* Load files given in ARGV */
  99.         
  100.         graf_mouse(ARROW, NULL);    /*    Initialize the mouse.    */
  101.     }
  102. }
  103.  
  104. /*
  105.     name: open_vwork
  106.     utility: Open a virtual workstation.
  107.     comment: a virtual workstation is associated with each window created.
  108.         This means that each window's graphic attributes are independent
  109.         of the other's.
  110.         Called from wind.c
  111.         Open a virtual workstation.
  112.         A virtual workstation is associated with each window created.
  113.         This means that each window's graphic attributes are independent
  114.         of the other's.
  115.     parameters: 
  116.     return: none
  117.     date: 1989
  118.     author: Jim Charlton
  119.     modifications:
  120.         1995: C.Moreau:
  121. */
  122. int open_vwork(register MFDB *form)
  123. {
  124.     int    dummy;
  125.     int vdi_handle = graf_handle(&gl_wchar, &gl_hchar, &dummy, &dummy);
  126.  
  127.     /*
  128.         Initialize workstation variables.
  129.     */
  130.     for(dummy=0; dummy<10; dummy++)
  131.         _GemParBlk.intin[dummy] = 1;
  132.     _GemParBlk.intin[10] = 2;
  133.  
  134.     v_opnvwk(_GemParBlk.intin, &vdi_handle, _GemParBlk.intout);
  135.  
  136.     form->fd_addr     = Logbase();
  137.     form->fd_w        = _GemParBlk.intout[0] + 1;
  138.     form->fd_h        = _GemParBlk.intout[1] + 1;
  139.     form->fd_wdwidth    = (form->fd_w + 15)/ 16;
  140.     form->fd_stand    = 0;
  141.  
  142.         /* take more infos    */
  143.     vq_extnd(vdi_handle, 1, _GemParBlk.intout);
  144.     form->fd_nplanes = _GemParBlk.intout[4];
  145.  
  146.         /* set default VDI param */
  147.     vsf_perimeter(vdi_handle,PERIMETER_OFF);
  148.     vsf_style(vdi_handle,1);
  149.     vsf_interior(vdi_handle, FIS_SOLID);            /* set for solid fill */
  150.     vst_alignment(vdi_handle,0,3,&dummy,&dummy);    /* set text alignment to bottom left */
  151.     vsf_color(vdi_handle, (black_white?0:1) );    /* paint color */
  152.  
  153.     return vdi_handle;
  154. }
  155.  
  156. /*
  157.     name: init_sys_vars
  158.     utility: Set TOS & AES version variables
  159.     comment: 
  160.     parameters: 
  161.     return: none
  162.     date: 1995
  163.     author: C.Moreau
  164.     modifications:
  165. */
  166. static void init_sys_vars(void)
  167. {
  168.     char **sysbase=(char **)0x4f2;        /* pointeur vers le debut du
  169.                                             systeme d'exploitation    */
  170.     char *systeme;                                                
  171.     long old_stack;
  172.  
  173.         /* Get TOS version */
  174.     if (!Super((void *)1L))    /* si on est en mode utilisateur    */
  175.         old_stack=Super(0L);    /* on passe en mode superviseur    */
  176.     systeme=*sysbase;            /* debut du systeme d'exploitation    */
  177.  
  178.     if (old_stack)                /* si on etait en utilisateur au debut    */
  179.         Super((void *)old_stack);    /*  on y retourne */                
  180.  
  181.     ver_tos = *(int *)(systeme+2);
  182.     
  183.         /* Get AES version */
  184.     ver_aes = _GemParBlk.global[0];
  185.  
  186.     app_get_path(app_path, PRG_NAME);    /* Get XXED.PRG path */
  187.  
  188.         /* Get size of screen */
  189.     wind_get(0, WF_WORKXYWH, &xdesk, &ydesk, &wdesk, &hdesk);
  190. }
  191.  
  192. /*
  193.     name: init_argv
  194.     utility:load all files given in the ARGV var
  195.     comment: You can give several files
  196.     parameters: 
  197.     return: none
  198.     date: 1995
  199.     author: C.Moreau
  200.     modifications:
  201. */
  202. static void init_argv(int *argc, char **argv[])
  203. {
  204.     register int cpt = 1;
  205.     const int thekind = UPARROW | DNARROW | VSLIDE | SIZER    \
  206.                         | MOVER | FULLER | CLOSER | NAME    \
  207.                         | INFO | SMALLER;
  208.     windowptr    thewin;
  209.  
  210.     while ( ((*argv)[cpt] != NULL) || (cpt < *argc) )
  211.     {
  212.         thewin = window_new(thekind);    
  213.         if (thewin)        /* Can open a new window */
  214.         {
  215.             strcpy(thewin->title, (*argv)[cpt++]); /* copy pathname to title */
  216.  
  217.             if    (read_file(thewin))
  218.                 window_open(thewin);
  219.             else
  220.                 window_resources_dispose(thewin);
  221.         }
  222.     }
  223. }
  224.